<template>
  <div>
    <SideMenu></SideMenu>
      <el-card style="width: 50%;height:400px;margin: 50px auto">
        <h2> 添加章节 </h2>
        <el-form v-model="form" style="text-align: left" ref="formRel" :model="form">
        <el-form-item label="章名称" :label-width="formLabelWidth" prop="sessionname">
          <el-input v-model="form.sessionname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="章名称" :label-width="formLabelWidth" prop="chaptername">
          <el-input v-model="form.chaptername" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="节名称" :label-width="formLabelWidth" prop="lessonname">
          <el-input v-model="form.lessonname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="url" :label-width="formLabelWidth" prop="url">
          <el-input v-model="form.url" autocomplete="off"></el-input>
        </el-form-item>
        <el-button style="margin-left: 220px"  @click="resetForm">重 置</el-button>
        <el-button style="margin-left: 50px" type="primary" @click="onSubmit">确 定</el-button>
      </el-form>
      </el-card>
  </div>
</template>

<script>
    import SideMenu from "./SideMenu";
  export default {
      components: {SideMenu},
    name: 'addSession',
    data () {
      return {
        form: {
            sessionname: '',
            chaptername: '',
            lessonname: '',
            url: '',
          // abs: '',
        },
          responseResult: [],
        formLabelWidth: '120px'
      }
    },
    methods: {
        resetForm () {
            console.log(this)
            this.$refs.formRel.resetFields()
        },
      onSubmit () {
        this.$axios
          .post('/addsession', {
              sessionname: this.form.sessionname,
              chaptername: this.form.chaptername,
              lessonname: this.form.lessonname,
              url: this.form.url
          }).then(resp => {
          if (resp && resp.status === 200) {
            this.dialogFormVisible = false
              this.$message.success('添加成功');
              this.resetForm()

          }
            else if (successResponse.data.code === 400){
                this.$message.error('添加失败');
            }
            else{
                this.$message.error('存在相同名字的课程');
            }
        })
      }
    }
  }
</script>

<style scoped>
  .el-icon-circle-plus-outline {
    margin: 50px 0 0 20px;
    font-size: 100px;
    float: left;
    cursor: pointer;
  }
</style>
